﻿namespace MSSqlSchemaDoc.Core.DataStructures
{
    using System.Xml;
    using System.Xml.Serialization;

    /// <summary>
    /// Provides a default implementation for the <see cref="IDataStructureObject">IDataStructureObject</see> interface.
    /// </summary>
    public abstract class DataStructureObjectBase : IDataStructureObject
    {
        /// <summary>
        /// Gets or sets the type of object represented.
        /// </summary>
        [XmlIgnore()]
        public virtual DataStructureObjectType ObjectType { get; set; }

        /// <summary>
        /// Gets or sets the internal id of the object.
        /// </summary>
        [XmlIgnore()]
        public int ObjectId { get; set; }

        /// <summary>
        /// Gets or sets the name of the object excluding the schema.
        /// </summary>
        [XmlAttribute()]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the schema to which the object belongs.
        /// </summary>
        [XmlAttribute()]
        public string Schema { get; set; }

        /// <summary>
        /// Gets or sets the documentation object.
        /// </summary>
        [XmlIgnore()]
        public IDocumentationObject Documentation { get; set; }

        /// <summary>
        /// Provide a meaningful string with the full object name.
        /// </summary>
        /// <returns>The object name and schema.</returns>
        public override string ToString()
        {
            if (string.IsNullOrEmpty(this.Schema))
            {
                return this.Name;
            }
            else
            {
                return string.Concat(this.Name, "_", this.Schema);
            }
        }
    }
}
